package com.luyou.module.system.service.auth;

import cn.hutool.core.collection.CollectionUtil;
import com.luyou.framework.security.core.LoginUser;
import com.luyou.module.system.dal.dataobject.SystemUsers;
import com.luyou.module.system.service.user.SystemUsersService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * @author luyou
 * @version 1.0
 * @date 2024/7/8 21:29
 * @desc
 */
@Service
public class AuthUserServiceImpl implements AuthUserService {

    @Resource
    private SystemUsersService systemUsersService;

    @Override
    public LoginUser login(String username, String password) {
        List<SystemUsers> systemUserList = systemUsersService.getUserName(username);
        if(CollectionUtil.isEmpty(systemUserList)){
            return null;
        }
        for (SystemUsers systemUsers : systemUserList) {
            if(password.equals(systemUsers.getPassword())){
               return LoginUser.builder().id(systemUsers.getId()).username(systemUsers.getUsername()).build();
            }

        }
        return null;
    }
}
